package p.ithorns.sample.influxdb.core;

import com.influxdb.utils.Arguments;

import javax.annotation.Nonnull;
import java.io.Serializable;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * QueryRecord
 *
 * @author HtL
 * @date 2025/1/17 13:58
 * @since 1.0.0
 */
public final class QueryRecord implements Serializable {

    private Series series;

    private final LinkedHashMap<String, Object> values = new LinkedHashMap<>();

    public LinkedHashMap<String, Object> getValues() {
        return values;
    }

    public Series getSeries() {
        return series;
    }

    public void setSeries(Series series) {
        this.series = series;
    }

    @Override
    public String toString() {
        return "{" +
                "series:" + series +
                ", values:" + values +
                "}";
    }

    public static class Series {

        @Nonnull
        private final String name;

        @Nonnull
        private final Map<String, String> tags;

        @Nonnull
        private final Map<String, Integer> columns;
        public Series(final @Nonnull String name, final @Nonnull Map<String, Integer> columns) {
            this(name, new HashMap<>(), columns);
        }

        public Series(final @Nonnull String name,
                      final @Nonnull Map<String, String> tags,
                      final @Nonnull Map<String, Integer> columns) {
            Arguments.checkNotNull(name, "name");
            Arguments.checkNotNull(tags, "tags");
            Arguments.checkNotNull(columns, "columns");

            this.name = name;
            this.tags = tags;
            this.columns = columns;
        }

        /**
         * @return the name
         */
        @Nonnull
        public String getName() {
            return this.name;
        }

        /**
         * @return the tags
         */
        @Nonnull
        public Map<String, String> getTags() {
            return this.tags;
        }

        /**
         * @return the columns
         */
        @Nonnull
        public Map<String, Integer> getColumns() {
            return this.columns;
        }

        @Override
        public String toString() {
            return "{" +
                    "name:'" + name + '\'' +
                    ", tags:" + tags +
                    ", columns:" + columns +
                    "}";
        }
    }

}